package com.orhon.smartcampus.modules.base.mm;


import com.orhon.smartcampus.modules.base.gqlModel.GQLPageParam;
import graphql.schema.DataFetchingEnvironment;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

@Mapper
public interface EnvArgsMapper {


    EnvArgsMapper MAPPER = Mappers.getMapper(EnvArgsMapper.class);

    /**
     *
     * 手写转化器
     * @param env
     * @return
     */
    default GQLPageParam fromArgs(DataFetchingEnvironment env){
        GQLPageParam p = new GQLPageParam();
        if (env.containsArgument("page")){
            p.setPage(env.getArgument("page"));
        }
        else{
            p.setPage(1);
        }
        if (env.containsArgument("limit")){
            p.setLimit(env.getArgument("limit"));
        }
        else{
            p.setLimit(10);
        }
        return p;
    }
}
